$(function() {
	$('#vue_vm_list').hide();
});

function lease_findLeaseRecord() {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list').hide();
	var startYear = $('#startYear').val();
	var startMonth = $('#startMonth').val();
	var startDay = $('#startDay').val();
	var endYear = $('#endYear').val();
	var endMonth = $('#endMonth').val();
	var endDay = $('#endDay').val();
	var startTime = getStandardDay(startYear, startMonth, startDay);
	var endTime = getStandardDay(endYear, endMonth, endDay);
	
	if(isEmpty(startYear)) {
		alert('请输入开始年');
		return;
	}
	if(isEmpty(startMonth)) {
		alert('请选择开始月');
		return;
	}
	if(isEmpty(startDay)) {
		alert('请选择开始日');
		return;
	}
	if(isEmpty(endYear)) {
		alert('请输入结束年');
		return;
	}
	if(isEmpty(endMonth)) {
		alert('请选择结束月');
		return;
	}
	if(isEmpty(endDay)) {
		alert('请选择结束日');
		return;
	}
	if(isEmpty(startTime)) {
		alert('请输入开始时间');
		return;
	}
	if(isEmpty(endTime)) {
		alert('请输入结束时间');
		return;
	}
	
	find_basic_by_json(path+'/lease/findLeaseRecord',
		{dateSince: startTime, dateEnd: endTime}, function(response) {	
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		response.total = {};
		response.total.leaseCount = response.data.length;
		response.total.officialPledge = 0;
		response.total.officialRent = 0;
		
		response.leasing = {};
		response.leasing.leaseCount = 0;
		response.leasing.officialPledge = 0;
		response.leasing.officialRent = 0;
		
		response.returned = {};
		response.returned.leaseCount = 0;
		response.returned.officialPledge = 0;
		response.returned.officialRent = 0;
		response.returned.returnRent = 0;
		response.returned.returnMoney = 0;
		response.returned.offsetMoney = 0;
		
		response.return01 = {};
		response.return01.leaseCount = 0;
		response.return01.officialPledge = 0;
		response.return01.returnRent = 0;
		
		response.return02 = {};
		response.return02.leaseCount = 0;
		response.return02.officialPledge = 0;
		response.return02.returnRent = 0;
		
		response.return03 = {};
		response.return03.leaseCount = 0;
		response.return03.officialPledge = 0;
		response.return03.returnRent = 0;
		
		for(var i=0; i<response.data.length; i++) {
			response.total.officialPledge += response.data[i].officialPledge;
			response.total.officialRent += response.data[i].officialRent;
			
			if(response.data[i].leaseStatus==1) {
				response.leasing.leaseCount += 1;
				response.leasing.officialPledge += response.data[i].officialPledge;
				response.leasing.officialRent += response.data[i].officialRent;
			}else {
				var returnRent = (response.data[i].returnMoney - response.data[i].offsetMoney - response.data[i].officialPledge);
				
				response.returned.leaseCount += 1;
				response.returned.officialPledge += response.data[i].officialPledge;
				response.returned.returnMoney += response.data[i].returnMoney;
				response.returned.offsetMoney += response.data[i].offsetMoney;
				response.returned.returnRent += returnRent;
				
				if(returnRent > 0) {
					response.return01.leaseCount += 1;
					response.return01.officialPledge += response.data[i].officialPledge;
					response.return01.returnRent += returnRent;
				}else if(returnRent < 0) {
					response.return02.leaseCount += 1;
					response.return02.officialPledge += response.data[i].officialPledge;
					response.return02.returnRent += -returnRent;
				}else { //也就是if(returnRent == 0)
					response.return03.leaseCount += 1;
					response.return03.officialPledge += response.data[i].officialPledge;
					response.return03.returnRent += 0;
				}
			}
		}
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				total: response.total,
				leasing: response.leasing,
				returned: response.returned,
				return01: response.return01,
				return02: response.return02,
				return03: response.return03
			}
		});
		
		$('#vue_vm_list').show();
	});
}